#include<stdio.h>
#define ERROR 999999999
int min=ERROR,book[101],e[101][101],n,start;
void dfs(int cur,int dis)//cur is city,dis is distance
{
    int j;
    if(dis>min) return;
    if(cur==n)
    {
        if(dis<min) min=dis;
        return;
    }
    for(j=1;j<=n;j++)
    {
        if(e[cur][j]!=ERROR&&book[j]==0)
        {
            book[j]=1;
            dfs(j,dis+e[cur][j]);
            book[j]=0;
        }
    }
}
int main()
{
    int i,j,m,a,b,c;
    printf("Please input start and end:\n");
    scanf("%d%d",&start,&n);
    printf("Please input how many lines in this city?\n");
    scanf("%d",&m);
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(i==j)    e[i][j]=0;
            else        e[i][j]=ERROR;
    printf("Please input lines and distance:\n");
    for(i=1;i<=m;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        e[a][b]=c;
        e[b][a]=c; //此处道路为单向，若加此代码即为双向
    }
    book[1]=1;
    dfs(start,0);
    printf("The minimum distance is %d",min);   
    return 0;
}